/*
 * TepcoMeter:TepcoMetterWidgetProvider.java
 * Copyright © 2011 ho9ho9 All Rights Reserved.
 */
package com.ho9ho9.tepcometer;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.widget.RemoteViews;

/**
 * TepcoMetterWidgetProviderクラス.
 * @author ho9ho9
 */
public class TepcoMetterWidgetProvider extends AppWidgetProvider {
	public static final Uri CONTENT_URI = Uri.parse("content://com.ho9ho9.tepcometer");
	
	@Override
	public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
		// 既存処理開始
		super.onUpdate(context, appWidgetManager, appWidgetIds);
		
		// サービスからWidget更新処理
		Intent serviceIntent = new Intent(context, TepcoMetterWidgetService.class);
		context.startService(serviceIntent);
		for (int id : appWidgetIds) {
			// Activity起動
			Intent intent = new Intent(context, TepcoMetterActivity.class);
			intent.setData(ContentUris.withAppendedId(CONTENT_URI, id));
			PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent, 0);
			RemoteViews rViews = new RemoteViews(context.getPackageName(), R.layout.widget);
			// イベント登録
			rViews.setOnClickPendingIntent(R.id.widgetLayoutArea, pIntent);
			appWidgetManager.updateAppWidget(id, rViews);
		}
	}
}
